/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: user
 * Date: 2023-06-18
 * Time: 14:42
 */
 class MyCircularQueue {
        private int [] elem;
        private int front;
        private int rear;
        public MyCircularQueue(int k){
            this.elem = new int [k+1];
        }
        //入队
        public boolean enQueue(int val){
            if (isFull()){
                return false;
            }
            elem[rear] = val;
            rear=(rear+1)% elem.length;
            return true;
        }
        //出队
        public boolean deQueue(){
            if (isempty()){
                return false;
            }
            front=(front+1)%elem.length;
            return true;
        }
        //得到队头元素
        public int Front(){
            if (isempty()){
                return -1;
            }
            return elem[front];
        }

        //得到队尾元素
        public int Rear(){
            if (isempty()){
                return -1;
            }
           int index =(rear ==0)?elem.length-1:rear-1;
            return elem[index];
        }

        public boolean isempty(){
            return rear==front;
        }

        public boolean isFull(){
            return (rear +1 ) %elem.length ==front;
        }
}
